/*
package org.itboys.mobile.service.mongo.front;

import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.framework.resource.ResourceHolder;
import org.itboys.mobile.common.SundayCommonConstants;
import org.itboys.mobile.dto.SundayCommunityDynamicDto;
import org.itboys.mobile.dto.SundayCommunityDynamicProductDto;
import org.itboys.mobile.dto.SundayPersonalDto;
import org.itboys.mobile.entity.mongo.SundayCommunityDynamic;
import org.itboys.mobile.entity.mongo.SundayCommunityDynamicProduct;
import org.itboys.mobile.entity.mongo.SundayMember;
import org.itboys.mobile.service.mongo.web.SundayMemberService;
import org.itboys.mobile.service.mysql.web.product.SundayProductService;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseMongoService;
import org.itboys.param.PageResult;
import org.itboys.param.ParamUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

*/
/**
 * Created by zhangyang on 2018/1/8.
 * 圣代_社区动态_service(微信圈/本地爱购/特别关注/达人试用)
 *//*

@Service
public class SundayFrontCommunityDynamicService extends BaseMongoService<SundayCommunityDynamic>{
    @Resource(name = "mobileDs")
    private MongoDataSource sundayDataSource;
    @Override
    protected MongoDataSource getMongoDataSource() {
        return sundayDataSource;
    }

    @Override
    protected Class<SundayCommunityDynamic> getEntityClass() {
        return SundayCommunityDynamic.class;
    }

    @Autowired
    private SundayProductService productService;
    @Autowired
    private SundayMemberService memberService;
    @Autowired
    private SundayFrontPraiseRecordService praiseRecordService;
    @Autowired
    private SundayFrontCommentService commentService;
    @Autowired
    private ResourceHolder resourceHolder;
    @Autowired
    private SundayFrontCollectionService collectionService;
    @Autowired
    private SundayFrontCommunityDynamicProductService communityDynamicProductService;

    */
/**
     * 保存社区动态:微信圈/达人试用/本地爱购
     * @param memberId  用户id
     * @param type  类别:1-微信圈,2-达人试用,3-本地爱购
     * @param productIds    产品id
     * @param mainId 评论实体id
     *//*

    public void save(Long memberId,Integer type,List<Long> productIds,Long mainId){
        SundayCommunityDynamic communityDynamic = new SundayCommunityDynamic();
        communityDynamic.setMemberId(memberId);
        communityDynamic.setType(type);
        communityDynamic.setCommentMainId(mainId);

        //除达人试用其他类别设置地区id,从而匹配查询出本地爱购动态
        if(type != SundayCommonConstants.community_dynamic_tryout){
            SundayMember member = memberService.getById(memberId);
            communityDynamic.setAreaId(member.getCityId());
        }
        saveCommunityAndProduct(communityDynamic,productIds);
    }

    */
/**
     * 保存社区动态及商品
     * @param communityDynamic  动态实体
     * @param productIds    商品ids
     *//*

    public void saveCommunityAndProduct(SundayCommunityDynamic communityDynamic,List<Long> productIds){
        super.save(communityDynamic);
        //保存动态的商品数据
        List<SundayCommunityDynamicProduct> productList = new ArrayList<SundayCommunityDynamicProduct>();
        for(Long id : productIds){
            SundayCommunityDynamicProduct dynamicProduct = new SundayCommunityDynamicProduct(communityDynamic.getId(),id);
            productList.add(dynamicProduct);
        }
        communityDynamicProductService.batchSave(productList);
    }

    */
/**
     * 保存社区动态:达人试用
     * @param memberId  用户id
     * @param productIds 产品id
     * @param image     图片,多个图片以,号分隔
     * @param content   试用内容
     *//*

    public void save(Long memberId,List<Long> productIds,String image,String content){
        SundayCommunityDynamic communityDynamic = new SundayCommunityDynamic();
        communityDynamic.setType(SundayCommonConstants.community_dynamic_tryout);
        communityDynamic.setMemberId(memberId);
        communityDynamic.setTryoutContent(content);
        communityDynamic.setTryoutImage(image);
        saveCommunityAndProduct(communityDynamic,productIds);
    }


    */
/**
     * 获取dto
     * @param type  类别:1-微信圈,2-达人试用,3-本地爱购,4-特殊关注,5-个人中心
     * @param memberIds  关注的用户id集合
     * @param memberId 当前登录用户id(本地爱购需要匹配登录用户的地区id,从而获取数据)
     * @return  dto
     *//*

    public List<SundayCommunityDynamicDto> select(Integer type, List<Long> memberIds, Long memberId, HttpServletRequest request){
        List<SundayCommunityDynamicDto> dtoList = new ArrayList<SundayCommunityDynamicDto>();

        Map<String,String> containsparam = ParamUtil.packageMongoVagueParam(request, "");
        Map<String,Object> param = new HashMap<String,Object>();
        param.put("isDeleted", SundayCommonConstants.NO);

        if(type == SundayCommonConstants.community_dynamic_special){//4.特殊关注
            //特殊关注,查询出关注的所有用户,查询用户的动态
            memberIds = collectionService.selectCollection(memberId,SundayCommonConstants.collection_type_member);
            if(ListUtil.isNull(memberIds)){
                return dtoList;
            }
            param.put("memberId in",memberIds);
        }else if(type == SundayCommonConstants.community_dynamic_circle){//1.微信圈
            if(ListUtil.isNull(memberIds)){
                return dtoList;
            }
            //排除评论动态
            List<Integer> typeList = new ArrayList<Integer>();
            typeList.add(SundayCommonConstants.community_dynamic_comment);
            param.put("type nin",typeList);
            param.put("memberId in",memberIds);
        }else if(type == SundayCommonConstants.community_dynamic_aigou){//3.本地爱购
            SundayMember member = memberService.getById(memberId);
            //排除评论动态
            List<Integer> typeList = new ArrayList<Integer>();
            typeList.add(SundayCommonConstants.community_dynamic_comment);
            param.put("type nin",typeList);
            param.put("areaId",member.getCityId());
        }else if(type == SundayCommonConstants.community_dynamic_tryout){//2.达人试用
            param.put("type",type);
        }else if(type == SundayCommonConstants.community_dynamic_personal){//5.个人中心
            if(ListUtil.isNull(memberIds)){
                return dtoList;
            }
            param.put("memberId in",memberIds);
        }

        PageResult<SundayCommunityDynamic> pageResult = super.containpageQuery(request,containsparam, param);
        List<SundayCommunityDynamic> list = pageResult.getData();

        //组装dto
        dtoList = packageDtoMuilt(list,memberId);
        return dtoList;
    }

    */
/**
     * 组装dto(多)
     *//*

    public List<SundayCommunityDynamicDto> packageDtoMuilt(List<SundayCommunityDynamic> list, Long memberId){
        List<SundayCommunityDynamicDto> dtoList = new ArrayList<SundayCommunityDynamicDto>();

        List<Long> dynamicIds = new ArrayList<Long>();
        List<Long> memberIds = new ArrayList<Long>();
        for(SundayCommunityDynamic communityDynamic : list){
            //如果是评论动态,则页面显示被评论的动态的商品
            if(communityDynamic.getType() == SundayCommonConstants.community_dynamic_comment){
                dynamicIds.add(communityDynamic.getCommentMainId());
            }else{
                dynamicIds.add(communityDynamic.getId());
            }
            memberIds.add(communityDynamic.getMemberId());
        }
        Map<String,Object> param = new HashMap<String,Object>();
        param.put("isDeleted",SundayCommonConstants.NO);
        param.put("id in",memberIds);
        List<SundayMember> memberList = memberService.list(param);

        //动态商品
        List<SundayCommunityDynamicProductDto> dynamicProductDtoList = communityDynamicProductService.selectProductDto(dynamicIds);
        for(SundayCommunityDynamic communityDynamic : list){
            SundayCommunityDynamicDto dto = packageDtoSingle(communityDynamic,memberId,memberList,dynamicProductDtoList);
            dtoList.add(dto);
        }
        return dtoList;
    }

    */
/**
     * 组装dto(单)
     *//*

    public SundayCommunityDynamicDto packageDtoSingle(SundayCommunityDynamic communityDynamic, Long memberId,List<SundayMember> memberList,List<SundayCommunityDynamicProductDto> dynamicProductDtoList){
        String imgRoot = resourceHolder.getStringValue("imgRoot");
        SundayMember member = null;
        for(SundayMember sundayMember : memberList){
            if(sundayMember.getId() == communityDynamic.getMemberId()){
                member = sundayMember;
                break;
            }
        }
        Map<String,Object> param = new HashMap<String,Object>();

        SundayCommunityDynamicDto dto = new SundayCommunityDynamicDto();
        dto.setCommentMainId(communityDynamic.getCommentMainId());
        dto.setTime(communityDynamic.getCreateTime());
        dto.setId(communityDynamic.getId());

        //用户信息
        dto.setMemberNickName(member.getNickName());
        dto.setMemberImage(imgRoot+member.getImage());
        dto.setMemberId(communityDynamic.getMemberId());
        dto.setType(communityDynamic.getType());

        //评论动态
        if(communityDynamic.getType() == SundayCommonConstants.community_dynamic_comment){
            //如果是评论动态,则商品信息显示的是被评论的动态的商品
            communityDynamic = super.getById(communityDynamic.getCommentMainId());
        }else if(communityDynamic.getType() == SundayCommonConstants.community_dynamic_circle){//微信圈
            //点赞数
            Long praiseCount = getCount(communityDynamic.getId(),SundayCommunityDynamic.class.getName(),1);
            //评论数
            Long commentCount = getCount(communityDynamic.getId(),SundayCommunityDynamic.class.getName(),2);
            dto.setPraiseCount(praiseCount);
            dto.setCommentCount(commentCount);
            //是否点过赞
            Integer isPraise = isResult(memberId,SundayCommunityDynamic.class.getName(),communityDynamic.getId(),1);
            dto.setIsPraise(isPraise);
            //是否关注过
            Integer isFollow = isResult(memberId,null,communityDynamic.getId(),2);
            dto.setIsFollow(isFollow);
        }else if(communityDynamic.getType() == SundayCommonConstants.community_dynamic_aigou){//本地爱购显示地区信息
            dto.setAreaName(member.getCityName());
            //点赞数
            Long praiseCount = getCount(communityDynamic.getId(),SundayCommunityDynamic.class.getName(),1);
            //评论数
            Long commentCount = getCount(communityDynamic.getId(),SundayCommunityDynamic.class.getName(),2);
            dto.setPraiseCount(praiseCount);
            dto.setCommentCount(commentCount);
            //是否点过赞
            Integer isPraise = isResult(memberId,SundayCommunityDynamic.class.getName(),communityDynamic.getId(),1);
            dto.setIsPraise(isPraise);
            //是否关注过
            Integer isFollow = isResult(memberId,null,communityDynamic.getId(),2);
            dto.setIsFollow(isFollow);
        }else if(communityDynamic.getType() == SundayCommonConstants.community_dynamic_tryout){//达人试用显示试用内容和图片
            dto.setContent(communityDynamic.getTryoutContent());
            List<String> images = new ArrayList<String>();
            if(communityDynamic.getTryoutImage().indexOf(",") != -1){//多个图片
                String[] image = communityDynamic.getTryoutImage().split(",");
                for(String img : image){
                    images.add(imgRoot+img);
                }
            }else{//单张图片
                images.add(imgRoot+communityDynamic.getTryoutImage());
            }
            dto.setImages(images);

            //点赞数
            Long praiseCount = getCount(communityDynamic.getId(),SundayCommunityDynamic.class.getName(),1);
            dto.setPraiseCount(praiseCount);
            //是否点过赞
            Integer isPraise = isResult(memberId,SundayCommunityDynamic.class.getName(),communityDynamic.getId(),1);
            dto.setIsPraise(isPraise);
            //是否关注过
            Integer isFollow = isResult(memberId,null,communityDynamic.getId(),2);
            dto.setIsFollow(isFollow);
        }

        //商品信息
        List<SundayCommunityDynamicProductDto> list = new ArrayList<SundayCommunityDynamicProductDto>();
        for(SundayCommunityDynamicProductDto dynamicProductDto : dynamicProductDtoList){
            if(dynamicProductDto.getMainId() == communityDynamic.getId()){
                list.add(dynamicProductDto);
            }
        }
//        List<SundayCommunityDynamicProductDto> dynamicProductDtoList = communityDynamicProductService.selectProductDto(communityDynamic.getId());
        dto.setProducts(list);
        return dto;
    }

    */
/**
     * 获取是否关注过或点过赞
     * @param memberId
     * @param outClassName
     * @param outClassId
     * @param type  1-获取是否点过赞,2-获取是否关注过
     * @return
     *//*

    public Integer isResult(Long memberId,String outClassName,Long outClassId,Integer type){
        Integer result = 0;
        if(type ==1){//是否点过赞
            Long count = praiseRecordService.check(memberId,outClassName,outClassId);
            if(count != 0L){//点过赞
                result = 1;
            }
        }else{//是否关注过
            result = collectionService.checkIsCollection(memberId,SundayCommonConstants.collection_type_member,outClassId);
        }
        return result;
    }

    */
/**
     * 获取点赞/评论数量
     * @param outClassId
     * @param outClassName
     * @param type 1-获取点赞数,2-获取评论数
     * @return
     *//*

    public Long getCount(Long outClassId,String outClassName,Integer type){
        Map<String,Object> param = new HashMap<String,Object>();
        param.put("isDeleted", SundayCommonConstants.NO);
        param.put("outClassId",outClassId);
        param.put("outClassName",outClassName);
        Long count = 0L;
        if(type ==1){
            count = praiseRecordService.count(param);
        }else{
            count = commentService.count(param);
        }
        return count;
    }


    */
/**
     * 获取单个详情dto
     * @param id
     * @return
     *//*

    public SundayCommunityDynamicDto getDetailDto(Long id,Long memberId){
        SundayCommunityDynamic communityDynamic = super.getById(id);
        //如果是评论动态则dto展示的为评论对应的微信圈/达人试用/本地爱购信息
        if(communityDynamic.getType() == SundayCommonConstants.community_dynamic_comment){
            communityDynamic = super.getById(communityDynamic.getCommentMainId());
        }

        List<SundayMember> memberList = new ArrayList<SundayMember>();
        memberList.add(memberService.getById(memberId));

        List<Long> dynamicIds = new ArrayList<Long>();
        dynamicIds.add(communityDynamic.getId());

        //动态商品
        List<SundayCommunityDynamicProductDto> dynamicProductDtoList = communityDynamicProductService.selectProductDto(dynamicIds);
        SundayCommunityDynamicDto dto = packageDtoSingle(communityDynamic,memberId,memberList,dynamicProductDtoList);
        return dto;
    }

    */
/**
     * 组装个人中心dto
     * @param memberId
     * @return
     *//*

    public SundayPersonalDto packagePersonalDtoSingle(Long memberId,HttpServletRequest request){
        String imgRoot = resourceHolder.getStringValue("imgRoot");
        SundayMember member = memberService.getById(memberId);
        //关注用户id
        List<Long> followList = collectionService.selectCollection(memberId,SundayCommonConstants.collection_type_member);
        //粉丝用户id
        List<Long> beFollowList = collectionService.selectBeCollection(memberId,SundayCommonConstants.collection_type_member);
        SundayPersonalDto dto = new SundayPersonalDto(memberId,member.getNickName(),imgRoot+member.getImage(),followList.size(),beFollowList.size());
        return dto;
    }

    */
/**
     * 获取个人中心分页数据
     * @param memberId
     * @param request
     * @return
     *//*

    public List<SundayCommunityDynamicDto> selectPersonal(Long memberId,HttpServletRequest request){
        List<Long> ids = new ArrayList<Long>();
        ids.add(memberId);
        List<SundayCommunityDynamicDto> list = select(SundayCommonConstants.community_dynamic_personal,ids,memberId,request);
        return list;
    }
}
*/
